package com.dynamixsoftware.printershare.smb;

import com.dynamixsoftware.printershare.smb.dcerpc.DcerpcHandle;
import com.dynamixsoftware.printershare.smb.dcerpc.DcerpcMessage;
import com.dynamixsoftware.printershare.smb.dcerpc.msrpc.MsrpcClosePrinter;
import com.dynamixsoftware.printershare.smb.dcerpc.msrpc.MsrpcGetPrinter;
import com.dynamixsoftware.printershare.smb.dcerpc.msrpc.MsrpcOpenPrinter;
import com.dynamixsoftware.printershare.smb.dcerpc.msrpc.MsrpcShareEnum;
import com.dynamixsoftware.printershare.smb.netbios.NbtAddress;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class SmbFile
  implements SmbConstants
{
  static final int ATTR_DIRECTORY = 16;
  private static final int ATTR_HIDDEN = 2;
  static final int ATTR_NORMAL = 128;
  static final int ATTR_READONLY = 1;
  private static final int ATTR_SYSTEM = 4;
  private static final int FILE_SHARE_DELETE = 4;
  private static final int FILE_SHARE_READ = 1;
  private static final int FILE_SHARE_WRITE = 2;
  private static final int HASH_DOT = ".".hashCode();
  private static final int HASH_DOT_DOT = "..".hashCode();
  static final int O_CREAT = 16;
  static final int O_EXCL = 32;
  static final int O_RDWR = 3;
  static final int O_TRUNC = 64;
  private static final int TYPE_COMM = 64;
  static final int TYPE_FILESYSTEM = 1;
  static final int TYPE_NAMED_PIPE = 16;
  public static final int TYPE_PRINTER = 32;
  public static final int TYPE_SERVER = 4;
  static final int TYPE_SHARE = 8;
  public static final int TYPE_WORKGROUP = 2;
  private static SmbOutpuStream sbmOutputStream;
  private int addressIndex;
  private UniAddress[] addresses;
  private NtlmPasswordAuthentication auth;
  private SmbComBlankResponse blank_resp = null;
  private String canon;
  int fid;
  boolean opened;
  private String share;
  private int shareAccess = 7;
  SmbTree tree = null;
  private int tree_num;
  int type;
  String unc;
  private URL url;
  
  private SmbFile(SmbFile paramSmbFile, String paramString, int paramInt1, int paramInt2, long paramLong1, long paramLong2, long paramLong3)
    throws MalformedURLException, UnknownHostException
  {}
  
  public SmbFile(String paramString)
    throws MalformedURLException
  {
    this(new URL(null, paramString, Handler.SMB_HANDLER));
  }
  
  public SmbFile(String paramString, NtlmPasswordAuthentication paramNtlmPasswordAuthentication)
    throws MalformedURLException
  {
    this(new URL(null, paramString, Handler.SMB_HANDLER), paramNtlmPasswordAuthentication);
  }
  
  private SmbFile(URL paramURL)
  {
    this(paramURL, new NtlmPasswordAuthentication(paramURL.getUserInfo()));
  }
  
  private SmbFile(URL paramURL, NtlmPasswordAuthentication paramNtlmPasswordAuthentication)
  {
    this.url = paramURL;
    if (paramNtlmPasswordAuthentication == null) {
      paramNtlmPasswordAuthentication = new NtlmPasswordAuthentication(paramURL.getUserInfo());
    }
    this.auth = paramNtlmPasswordAuthentication;
    getUncPath0();
  }
  
  private SmbComBlankResponse blank_resp()
  {
    if (this.blank_resp == null) {
      this.blank_resp = new SmbComBlankResponse();
    }
    return this.blank_resp;
  }
  
  private void close(int paramInt, long paramLong)
    throws SmbException
  {
    if (this.type != 32)
    {
      send(new SmbComClose(paramInt, paramLong), blank_resp());
      return;
    }
    send(new SmbComClosePrintFile(this.fid), blank_resp());
  }
  
  private void close(long paramLong)
    throws SmbException
  {
    if (!isOpen()) {
      return;
    }
    close(this.fid, paramLong);
    this.opened = false;
  }
  
  private void connect()
    throws IOException
  {
    if (isConnected()) {
      return;
    }
    getUncPath0();
    do
    {
      try
      {
        doConnect();
        return;
      }
      catch (SmbAuthException localSmbAuthException)
      {
        throw localSmbAuthException;
      }
      catch (IOException localIOException) {}
    } while (getNextAddress() != null);
    throw localIOException;
  }
  
  private void doConnect()
    throws IOException
  {
    UniAddress localUniAddress = getAddress();
    if (this.tree != null) {
      localSmbTransport = this.tree.session.transport;
    }
    for (;;)
    {
      try
      {
        this.tree.treeConnect(null, null);
        return;
      }
      catch (SmbAuthException localSmbAuthException)
      {
        if (this.share != null) {
          continue;
        }
        this.tree = localSmbTransport.getSmbSession(NtlmPasswordAuthentication.ANONYMOUS).getSmbTree(null, null);
        this.tree.treeConnect(null, null);
        return;
        NtlmPasswordAuthentication localNtlmPasswordAuthentication = NtlmAuthenticator.requestNtlmPasswordAuthentication(this.url.toString(), localSmbAuthException);
        if (localNtlmPasswordAuthentication == null) {
          continue;
        }
        this.auth = localNtlmPasswordAuthentication;
        this.tree = localSmbTransport.getSmbSession(this.auth).getSmbTree(this.share, null);
        this.tree.treeConnect(null, null);
        return;
        throw localSmbAuthException;
      }
      localSmbTransport = SmbTransport.getSmbTransport(localUniAddress, this.url.getPort());
      this.tree = localSmbTransport.getSmbSession(this.auth).getSmbTree(this.share, null);
    }
  }
  
  private void doEnum(ArrayList<Object> paramArrayList, boolean paramBoolean, String paramString, int paramInt)
    throws SmbException
  {
    try
    {
      if ((this.url.getHost().length() == 0) || (getType() == 2))
      {
        doNetServerEnum(paramArrayList, paramBoolean, paramString, paramInt);
        return;
      }
      if (this.share == null)
      {
        doShareEnum(paramArrayList, paramBoolean, paramString, paramInt);
        return;
      }
    }
    catch (UnknownHostException localUnknownHostException)
    {
      throw new SmbException(this.url.toString(), localUnknownHostException);
      doFindFirstNext(paramArrayList, paramBoolean, paramString, paramInt);
      return;
    }
    catch (MalformedURLException localMalformedURLException)
    {
      throw new SmbException(this.url.toString(), localMalformedURLException);
    }
  }
  
  private void doFindFirstNext(ArrayList<Object> paramArrayList, boolean paramBoolean, String paramString, int paramInt)
    throws SmbException, UnknownHostException, MalformedURLException
  {
    String str1 = getUncPath0();
    String str2 = this.url.getPath();
    if (str2.lastIndexOf('/') != -1 + str2.length()) {
      throw new SmbException(this.url.toString() + " directory must end with '/'");
    }
    Trans2FindFirst2 localTrans2FindFirst2 = new Trans2FindFirst2(str1, paramString, paramInt);
    Trans2FindFirst2Response localTrans2FindFirst2Response = new Trans2FindFirst2Response();
    send(localTrans2FindFirst2, localTrans2FindFirst2Response);
    int i = localTrans2FindFirst2Response.sid;
    Trans2FindNext2 localTrans2FindNext2 = new Trans2FindNext2(i, localTrans2FindFirst2Response.resumeKey, localTrans2FindFirst2Response.lastName);
    localTrans2FindFirst2Response.subCommand = 2;
    for (;;)
    {
      int j = 0;
      int k = localTrans2FindFirst2Response.numEntries;
      if (j < k)
      {
        FileEntry localFileEntry = localTrans2FindFirst2Response.results[j];
        String str3 = localFileEntry.getName();
        if (str3.length() < 3)
        {
          int m = str3.hashCode();
          if (((m != HASH_DOT) && (m != HASH_DOT_DOT)) || ((!str3.equals(".")) && (!str3.equals("..")))) {}
        }
        for (;;)
        {
          j++;
          break;
          if (str3.length() > 0)
          {
            SmbFile localSmbFile = new SmbFile(this, str3, 1, localFileEntry.getAttributes(), localFileEntry.createTime(), localFileEntry.lastModified(), localFileEntry.length());
            if (paramBoolean) {
              paramArrayList.add(localSmbFile);
            } else {
              paramArrayList.add(str3);
            }
          }
        }
      }
      if ((localTrans2FindFirst2Response.isEndOfSearch) || (localTrans2FindFirst2Response.numEntries == 0)) {}
      try
      {
        send(new SmbComFindClose2(i), blank_resp());
        return;
      }
      catch (SmbException localSmbException) {}
      localTrans2FindNext2.reset(localTrans2FindFirst2Response.resumeKey, localTrans2FindFirst2Response.lastName);
      localTrans2FindFirst2Response.reset();
      send(localTrans2FindNext2, localTrans2FindFirst2Response);
    }
  }
  
  private FileEntry[] doMsrpcShareEnum()
    throws IOException
  {
    MsrpcShareEnum localMsrpcShareEnum = new MsrpcShareEnum(this.url.getHost());
    DcerpcHandle localDcerpcHandle = DcerpcHandle.getHandle("ncacn_np:" + getAddress().getHostAddress() + "[\\PIPE\\srvsvc]", this.auth);
    try
    {
      localDcerpcHandle.sendrecv(localMsrpcShareEnum);
      if (localMsrpcShareEnum.retval != 0) {
        throw new SmbException(localMsrpcShareEnum.retval, true);
      }
    }
    finally {}
    try
    {
      localDcerpcHandle.close();
      label85:
      throw localObject;
      FileEntry[] arrayOfFileEntry = localMsrpcShareEnum.getEntries();
      try
      {
        localDcerpcHandle.close();
        return arrayOfFileEntry;
      }
      catch (IOException localIOException2)
      {
        return arrayOfFileEntry;
      }
    }
    catch (IOException localIOException1)
    {
      break label85;
    }
  }
  
  private void doNetServerEnum(ArrayList<Object> paramArrayList, boolean paramBoolean, String paramString, int paramInt)
    throws SmbException, UnknownHostException, MalformedURLException
  {
    int i;
    if (this.url.getHost().length() == 0) {
      i = 0;
    }
    label138:
    label211:
    int j;
    label239:
    label242:
    do
    {
      NetServerEnum2 localNetServerEnum2;
      NetServerEnum2Response localNetServerEnum2Response;
      for (;;)
      {
        try
        {
          connect0();
          if (i != 0) {
            break label138;
          }
          String str4 = this.tree.session.transport.server.oemDomainName;
          localNetServerEnum2 = new NetServerEnum2(str4, -2147483648);
          localNetServerEnum2Response = new NetServerEnum2Response();
          send(localNetServerEnum2, localNetServerEnum2Response);
          if ((localNetServerEnum2Response.status == 0) || (localNetServerEnum2Response.status == 234)) {
            break label211;
          }
          throw new SmbException(localNetServerEnum2Response.status, true);
        }
        catch (SmbException localSmbException)
        {
          if ((i != 0) || (!(localSmbException.getCause() instanceof UnknownHostException))) {
            continue;
          }
          return;
          throw localSmbException;
        }
        i = getType();
      }
      do
      {
        if (i == 2)
        {
          String str1 = this.url.getHost();
          localNetServerEnum2 = new NetServerEnum2(str1, -1);
          localNetServerEnum2Response = new NetServerEnum2Response();
          break;
        }
        throw new SmbException("The requested list operations is invalid: " + this.url.toString());
        int k;
        int m;
        String str3;
        if (localNetServerEnum2Response.status == 234)
        {
          j = 1;
          if (j == 0) {
            break label328;
          }
          k = -1 + localNetServerEnum2Response.numEntries;
          m = 0;
          if (m >= k) {
            continue;
          }
          FileEntry localFileEntry = localNetServerEnum2Response.results[m];
          str3 = localFileEntry.getName();
          if ((str3 != null) && (str3.length() > 0))
          {
            SmbFile localSmbFile = new SmbFile(this, str3, localFileEntry.getType(), 17, 0L, 0L, 0L);
            if (!paramBoolean) {
              break label338;
            }
            paramArrayList.add(localSmbFile);
          }
        }
        for (;;)
        {
          m++;
          break label242;
          j = 0;
          break;
          k = localNetServerEnum2Response.numEntries;
          break label239;
          paramArrayList.add(str3);
        }
      } while (getType() != 2);
      localNetServerEnum2.subCommand = -41;
      String str2 = ((NetServerEnum2Response)localNetServerEnum2Response).lastName;
      localNetServerEnum2.reset(0, str2);
      localNetServerEnum2Response.reset();
    } while (j != 0);
    label328:
    label338:
    return;
  }
  
  private FileEntry[] doNetShareEnum()
    throws SmbException
  {
    NetShareEnum localNetShareEnum = new NetShareEnum();
    NetShareEnumResponse localNetShareEnumResponse = new NetShareEnumResponse();
    send(localNetShareEnum, localNetShareEnumResponse);
    if (localNetShareEnumResponse.status != 0) {
      throw new SmbException(localNetShareEnumResponse.status, true);
    }
    return localNetShareEnumResponse.results;
  }
  
  private String[] doPrinterGetInfo()
    throws IOException
  {
    String str = getUncPath();
    if (str.endsWith("\\")) {
      str = str.substring(0, -1 + str.length());
    }
    MsrpcOpenPrinter localMsrpcOpenPrinter = new MsrpcOpenPrinter(str);
    DcerpcHandle localDcerpcHandle = DcerpcHandle.getHandle("ncacn_np:" + getAddress().getHostAddress() + "[\\PIPE\\spoolss]", this.auth);
    try
    {
      localDcerpcHandle.sendrecv(localMsrpcOpenPrinter);
      if (localMsrpcOpenPrinter.retval != 0) {
        throw new SmbException(localMsrpcOpenPrinter.retval, true);
      }
    }
    finally {}
    try
    {
      localDcerpcHandle.close();
      label106:
      throw localObject1;
      Object localObject2 = new MsrpcGetPrinter(localMsrpcOpenPrinter.getPrinteHandle(), 2, 0);
      localDcerpcHandle.sendrecv((DcerpcMessage)localObject2);
      if (((MsrpcGetPrinter)localObject2).retval == 122)
      {
        MsrpcGetPrinter localMsrpcGetPrinter = new MsrpcGetPrinter(localMsrpcOpenPrinter.getPrinteHandle(), 2, ((MsrpcGetPrinter)localObject2).pcbneeded);
        localDcerpcHandle.sendrecv(localMsrpcGetPrinter);
        localObject2 = localMsrpcGetPrinter;
      }
      if (((MsrpcGetPrinter)localObject2).retval != 0) {
        throw new SmbException(((MsrpcGetPrinter)localObject2).retval, true);
      }
      MsrpcClosePrinter localMsrpcClosePrinter = new MsrpcClosePrinter(localMsrpcOpenPrinter.getPrinteHandle());
      localDcerpcHandle.sendrecv(localMsrpcClosePrinter);
      if (localMsrpcClosePrinter.retval != 0) {
        throw new SmbException(localMsrpcClosePrinter.retval, true);
      }
      String[] arrayOfString = new String[4];
      arrayOfString[0] = ((MsrpcGetPrinter)localObject2).getPrinterName();
      arrayOfString[1] = ((MsrpcGetPrinter)localObject2).getDriverName();
      arrayOfString[2] = ((MsrpcGetPrinter)localObject2).getLocation();
      arrayOfString[3] = ((MsrpcGetPrinter)localObject2).getServerName();
      try
      {
        localDcerpcHandle.close();
        return arrayOfString;
      }
      catch (IOException localIOException2)
      {
        return arrayOfString;
      }
    }
    catch (IOException localIOException1)
    {
      break label106;
    }
  }
  
  private void doShareEnum(ArrayList<Object> paramArrayList, boolean paramBoolean, String paramString, int paramInt)
    throws SmbException, UnknownHostException, MalformedURLException
  {
    String str1 = this.url.getPath();
    Object localObject1 = null;
    if (str1.lastIndexOf('/') != -1 + str1.length()) {
      throw new SmbException(this.url.toString() + " directory must end with '/'");
    }
    if (getType() != 4) {
      throw new SmbException("The requested list operations is invalid: " + this.url.toString());
    }
    HashMap localHashMap = new HashMap();
    for (;;)
    {
      int i;
      try
      {
        doConnect();
        try
        {
          FileEntry[] arrayOfFileEntry2 = doMsrpcShareEnum();
          localObject2 = arrayOfFileEntry2;
        }
        catch (IOException localIOException2)
        {
          Object localObject3;
          FileEntry[] arrayOfFileEntry1 = doNetShareEnum();
          Object localObject2 = arrayOfFileEntry1;
          continue;
        }
        i = 0;
        if (i >= localObject2.length) {
          break label197;
        }
        localObject3 = localObject2[i];
        if (localHashMap.containsKey(localObject3)) {
          break label341;
        }
        localHashMap.put(localObject3, localObject3);
      }
      catch (IOException localIOException1)
      {
        localObject1 = localIOException1;
      }
      if (getNextAddress() == null)
      {
        label197:
        if ((localObject1 != null) && (localHashMap.isEmpty()))
        {
          if (!(localObject1 instanceof SmbException)) {
            throw new SmbException(this.url.toString(), localObject1);
          }
          throw ((SmbException)localObject1);
        }
        Iterator localIterator = localHashMap.keySet().iterator();
        while (localIterator.hasNext())
        {
          FileEntry localFileEntry = (FileEntry)localIterator.next();
          String str2 = localFileEntry.getName();
          if (str2.length() > 0)
          {
            SmbFile localSmbFile = new SmbFile(this, str2, localFileEntry.getType(), 17, 0L, 0L, 0L);
            if (paramBoolean) {
              paramArrayList.add(localSmbFile);
            } else {
              paramArrayList.add(str2);
            }
          }
        }
        return;
        label341:
        i++;
      }
    }
  }
  
  private UniAddress getAddress()
    throws UnknownHostException
  {
    if (this.addressIndex == 0) {
      return getFirstAddress();
    }
    return this.addresses[(-1 + this.addressIndex)];
  }
  
  private UniAddress getFirstAddress()
    throws UnknownHostException
  {
    this.addressIndex = 0;
    String str1 = this.url.getHost();
    String str2 = this.url.getPath();
    if (str1.length() == 0)
    {
      NbtAddress localNbtAddress = NbtAddress.getByName("\001\002__MSBROWSE__\002", 1, null);
      this.addresses = new UniAddress[1];
      this.addresses[0] = UniAddress.getByName(localNbtAddress.getHostAddress());
    }
    for (;;)
    {
      return getNextAddress();
      if ((str2.length() == 0) || (str2.equals("/"))) {
        this.addresses = UniAddress.getAllByName(str1, true);
      } else {
        this.addresses = UniAddress.getAllByName(str1, false);
      }
    }
  }
  
  private UniAddress getNextAddress()
  {
    UniAddress[] arrayOfUniAddress1 = this.addresses;
    UniAddress localUniAddress = null;
    if (arrayOfUniAddress1 != null)
    {
      int i = this.addressIndex;
      int j = this.addresses.length;
      localUniAddress = null;
      if (i < j)
      {
        UniAddress[] arrayOfUniAddress2 = this.addresses;
        int k = this.addressIndex;
        this.addressIndex = (k + 1);
        localUniAddress = arrayOfUniAddress2[k];
      }
    }
    return localUniAddress;
  }
  
  private String getUncPath0()
  {
    char[] arrayOfChar2;
    label234:
    int n;
    int i1;
    if (this.unc == null)
    {
      char[] arrayOfChar1 = this.url.getPath().toCharArray();
      arrayOfChar2 = new char[arrayOfChar1.length];
      int i = arrayOfChar1.length;
      int j = 0;
      int k = 0;
      int m = 0;
      if (k < i)
      {
        int i2;
        switch (j)
        {
        default: 
          i2 = m;
        }
        for (;;)
        {
          k++;
          break label234;
          m = i2;
          break;
          if (arrayOfChar1[k] != '/') {
            return null;
          }
          i2 = m + 1;
          arrayOfChar2[m] = arrayOfChar1[k];
          j = 1;
          continue;
          if (arrayOfChar1[k] == '/')
          {
            i2 = m;
          }
          else if ((arrayOfChar1[k] == '.') && ((k + 1 >= i) || (arrayOfChar1[(k + 1)] == '/')))
          {
            k++;
            i2 = m;
          }
          else if ((k + 1 < i) && (arrayOfChar1[k] == '.') && (arrayOfChar1[(k + 1)] == '.') && ((k + 2 >= i) || (arrayOfChar1[(k + 2)] == '/')))
          {
            k += 2;
            if (m == 1)
            {
              i2 = m;
            }
            else
            {
              i2 = m;
              i2--;
              if (i2 > 1) {
                if (arrayOfChar2[(i2 - 1)] == '/') {}
              }
            }
          }
          else
          {
            j = 2;
            if (arrayOfChar1[k] == '/') {
              j = 1;
            }
            i2 = m + 1;
            arrayOfChar2[m] = arrayOfChar1[k];
          }
        }
      }
      this.canon = new String(arrayOfChar2, 0, m);
      if (m <= 1) {
        break label452;
      }
      n = m - 1;
      i1 = this.canon.indexOf('/', 1);
      if (i1 >= 0) {
        break label356;
      }
      this.share = this.canon.substring(1);
      this.unc = "\\";
    }
    label452:
    for (;;)
    {
      return this.unc;
      label356:
      if (i1 == n)
      {
        this.share = this.canon.substring(1, i1);
        this.unc = "\\";
      }
      else
      {
        this.share = this.canon.substring(1, i1);
        String str = this.canon;
        if (arrayOfChar2[n] == '/') {}
        for (;;)
        {
          this.unc = str.substring(i1, n);
          this.unc = this.unc.replace('/', '\\');
          break;
          n++;
        }
        this.share = null;
        this.unc = "\\";
      }
    }
  }
  
  private boolean isConnected()
  {
    return (this.tree != null) && (this.tree.connectionState == 2);
  }
  
  private boolean isWorkgroup0()
    throws UnknownHostException
  {
    if ((this.type == 2) || (this.url.getHost().length() == 0))
    {
      this.type = 2;
      return true;
    }
    getUncPath0();
    if (this.share == null)
    {
      UniAddress localUniAddress = getAddress();
      if ((localUniAddress.getAddress() instanceof NbtAddress))
      {
        int i = ((NbtAddress)localUniAddress.getAddress()).getNameType();
        if ((i == 29) || (i == 27))
        {
          this.type = 2;
          return true;
        }
      }
      this.type = 4;
    }
    return false;
  }
  
  private SmbFile[] listFiles(String paramString, int paramInt)
    throws SmbException
  {
    ArrayList localArrayList = new ArrayList();
    doEnum(localArrayList, true, paramString, paramInt);
    return (SmbFile[])localArrayList.toArray(new SmbFile[localArrayList.size()]);
  }
  
  private int open0(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
    throws SmbException
  {
    if (this.tree.session.transport.hasCapability(16))
    {
      SmbComNTCreateAndXResponse localSmbComNTCreateAndXResponse = new SmbComNTCreateAndXResponse();
      SmbComNTCreateAndX localSmbComNTCreateAndX = new SmbComNTCreateAndX(this.unc, paramInt1, paramInt2, this.shareAccess, paramInt3, paramInt4, null);
      if ((this instanceof SmbNamedPipe))
      {
        localSmbComNTCreateAndX.flags0 = (0x16 | localSmbComNTCreateAndX.flags0);
        localSmbComNTCreateAndX.desiredAccess = (0x20000 | localSmbComNTCreateAndX.desiredAccess);
        localSmbComNTCreateAndXResponse.isExtended = true;
      }
      send(localSmbComNTCreateAndX, localSmbComNTCreateAndXResponse);
      return localSmbComNTCreateAndXResponse.fid;
    }
    SmbComOpenAndXResponse localSmbComOpenAndXResponse = new SmbComOpenAndXResponse();
    send(new SmbComOpenAndX(this.unc, paramInt2, paramInt1, null), localSmbComOpenAndXResponse);
    return localSmbComOpenAndXResponse.fid;
  }
  
  private void open_printJob(String paramString)
    throws SmbException
  {
    SmbComOpenPrintFile localSmbComOpenPrintFile = new SmbComOpenPrintFile(paramString);
    SmbComOpenPrintFileResponse localSmbComOpenPrintFileResponse = new SmbComOpenPrintFileResponse();
    send(localSmbComOpenPrintFile, localSmbComOpenPrintFileResponse);
    this.fid = ((int)localSmbComOpenPrintFileResponse.fid);
    this.opened = true;
    this.tree_num = this.tree.tree_num;
  }
  
  private boolean pathNamesPossiblyEqual(String paramString1, String paramString2)
  {
    int i = paramString1.lastIndexOf('/');
    int j = paramString2.lastIndexOf('/');
    int k = paramString1.length() - i;
    int m = paramString2.length() - j;
    if ((k > 1) && (paramString1.charAt(i + 1) == '.')) {}
    while (((m > 1) && (paramString2.charAt(j + 1) == '.')) || ((k == m) && (paramString1.regionMatches(true, i, paramString2, j, k)))) {
      return true;
    }
    return false;
  }
  
  private void print_write(byte[] paramArrayOfByte, int paramInt)
    throws IOException
  {
    send(new SmbComWritePrintFile(this.fid, paramInt, paramArrayOfByte), blank_resp());
  }
  
  public void close()
    throws SmbException
  {
    close(0L);
  }
  
  void connect0()
    throws SmbException
  {
    try
    {
      connect();
      return;
    }
    catch (UnknownHostException localUnknownHostException)
    {
      throw new SmbException("Failed to connect to server", localUnknownHostException);
    }
    catch (SmbException localSmbException)
    {
      throw localSmbException;
    }
    catch (IOException localIOException)
    {
      throw new SmbException("Failed to connect to server", localIOException);
    }
  }
  
  public boolean equals(Object paramObject)
  {
    if ((paramObject instanceof SmbFile))
    {
      SmbFile localSmbFile = (SmbFile)paramObject;
      if (this == localSmbFile) {
        return true;
      }
      if (pathNamesPossiblyEqual(this.url.getPath(), localSmbFile.url.getPath()))
      {
        getUncPath0();
        localSmbFile.getUncPath0();
        if (this.canon.equalsIgnoreCase(localSmbFile.canon)) {
          try
          {
            boolean bool = getAddress().equals(localSmbFile.getAddress());
            return bool;
          }
          catch (UnknownHostException localUnknownHostException)
          {
            return getServer().equalsIgnoreCase(localSmbFile.getServer());
          }
        }
      }
    }
    return false;
  }
  
  public String getName()
  {
    getUncPath0();
    if (this.canon.length() > 1)
    {
      for (int i = -2 + this.canon.length(); this.canon.charAt(i) != '/'; i--) {}
      return this.canon.substring(i + 1);
    }
    if (this.share != null) {
      return this.share + '/';
    }
    if (this.url.getHost().length() > 0) {
      return this.url.getHost() + '/';
    }
    return "smb://";
  }
  
  public String getPath()
  {
    return this.url.toString();
  }
  
  public Principal getPrincipal()
  {
    return this.auth;
  }
  
  public String getServer()
  {
    String str = this.url.getHost();
    if (str.length() == 0) {
      str = null;
    }
    return str;
  }
  
  public int getType()
    throws SmbException
  {
    if (this.type == 0)
    {
      if (getUncPath0().length() <= 1) {
        break label28;
      }
      this.type = 1;
    }
    for (;;)
    {
      return this.type;
      label28:
      if (this.share != null)
      {
        connect0();
        if (this.share.equals("IPC$")) {
          this.type = 16;
        } else if (this.tree.service.equals("LPT1:")) {
          this.type = 32;
        } else if (this.tree.service.equals("COMM")) {
          this.type = 64;
        } else {
          this.type = 8;
        }
      }
      else if ((this.url.getAuthority() == null) || (this.url.getAuthority().length() == 0))
      {
        this.type = 2;
      }
      else
      {
        try
        {
          UniAddress localUniAddress = getAddress();
          if ((localUniAddress.getAddress() instanceof NbtAddress))
          {
            int i = ((NbtAddress)localUniAddress.getAddress()).getNameType();
            if ((i == 29) || (i == 27))
            {
              this.type = 2;
              return this.type;
            }
          }
        }
        catch (UnknownHostException localUnknownHostException)
        {
          throw new SmbException(this.url.toString(), localUnknownHostException);
        }
        this.type = 4;
      }
    }
  }
  
  public String getUncPath()
  {
    getUncPath0();
    if (this.share == null) {
      return "\\\\" + this.url.getHost();
    }
    return "\\\\" + this.url.getHost() + this.canon.replace('/', '\\');
  }
  
  public int hashCode()
  {
    try
    {
      int j = getAddress().hashCode();
      i = j;
    }
    catch (UnknownHostException localUnknownHostException)
    {
      for (;;)
      {
        int i = getServer().toUpperCase().hashCode();
      }
    }
    getUncPath0();
    return i + this.canon.toUpperCase().hashCode();
  }
  
  boolean isOpen()
  {
    return (this.opened) && (isConnected()) && (this.tree_num == this.tree.tree_num);
  }
  
  public SmbFile[] listFiles()
    throws SmbException
  {
    return listFiles("*", 22);
  }
  
  void open(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
    throws SmbException
  {
    if (isOpen()) {
      return;
    }
    this.fid = open0(paramInt1, paramInt2, paramInt3, paramInt4);
    this.opened = true;
    this.tree_num = this.tree.tree_num;
  }
  
  public void print_close()
    throws IOException
  {
    close();
  }
  
  public SmbOutpuStream print_open(String paramString)
    throws IOException
  {
    connect0();
    if (getType() != 32) {
      return null;
    }
    open_printJob(paramString);
    sbmOutputStream = new SmbOutpuStream();
    return sbmOutputStream;
  }
  
  public String[] printerGetInfo()
    throws IOException
  {
    do
    {
      try
      {
        String[] arrayOfString = doPrinterGetInfo();
        return arrayOfString;
      }
      catch (SmbAuthException localSmbAuthException)
      {
        throw localSmbAuthException;
      }
      catch (IOException localIOException) {}
    } while (getNextAddress() != null);
    throw localIOException;
  }
  
  void send(ServerMessageBlock paramServerMessageBlock1, ServerMessageBlock paramServerMessageBlock2)
    throws SmbException
  {
    this.tree.send(paramServerMessageBlock1, paramServerMessageBlock2);
  }
  
  public void setAuth(NtlmPasswordAuthentication paramNtlmPasswordAuthentication)
  {
    this.auth = paramNtlmPasswordAuthentication;
  }
  
  public String toString()
  {
    return this.url.toString();
  }
  
  private class SmbOutpuStream
    extends OutputStream
  {
    private byte[] buf;
    private int bufLength;
    private int index;
    private int sndBufSize = SmbFile.this.tree.session.transport.snd_buf_size;
    
    public SmbOutpuStream()
    {
      if (this.sndBufSize <= 70) {}
      for (int i = this.sndBufSize;; i = -70 + this.sndBufSize)
      {
        this.buf = new byte[i];
        this.bufLength = this.buf.length;
        this.index = 0;
        return;
      }
    }
    
    public void close()
      throws IOException
    {
      flush();
    }
    
    public void flush()
      throws IOException
    {
      if (this.index != 0) {
        SmbFile.this.print_write(this.buf, this.index);
      }
      this.index = 0;
    }
    
    public void write(int paramInt)
      throws IOException
    {
      if (this.index < this.buf.length)
      {
        byte[] arrayOfByte2 = this.buf;
        int j = this.index;
        this.index = (j + 1);
        arrayOfByte2[j] = ((byte)paramInt);
        return;
      }
      SmbFile.this.print_write(this.buf, this.index);
      this.index = 0;
      byte[] arrayOfByte1 = this.buf;
      int i = this.index;
      this.index = (i + 1);
      arrayOfByte1[i] = ((byte)paramInt);
    }
    
    public void write(byte[] paramArrayOfByte)
      throws IOException
    {
      write(paramArrayOfByte, 0, paramArrayOfByte.length);
    }
    
    public void write(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      throws IOException
    {
      if (paramInt2 + this.index < this.bufLength)
      {
        System.arraycopy(paramArrayOfByte, paramInt1, this.buf, this.index, paramInt2);
        this.index = (paramInt2 + this.index);
        return;
      }
      int i = this.bufLength - this.index;
      System.arraycopy(paramArrayOfByte, paramInt1, this.buf, this.index, i);
      SmbFile.this.print_write(this.buf, this.bufLength);
      this.index = 0;
      write(paramArrayOfByte, paramInt1 + i, paramInt2 - i);
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.smb.SmbFile
 * JD-Core Version:    0.7.0.1
 */